package com.example.conusmer.service.impl


import com.example.common.entity.UserDubbo
import com.example.common.service.UserDubboService
import com.example.conusmer.entity.User
import com.example.conusmer.service.UserService
import org.apache.dubbo.config.annotation.DubboReference
import org.springframework.stereotype.Service

@Service
class UserServiceImpl : UserService {

    @DubboReference()
    lateinit var userService: UserDubboService

    override  fun list(): List<User> {
        val userList = userService.list()
       val resList = userList.map {
            User(it.id, it.name, it.email)
        }
        return resList
    }
    override fun getById(id: String): User? {
        val u =  userService.getById(id)
        val res = User(u?.id, u?.name, u?.email)
        return res
    }

    override fun create(item: User)= userService.create(UserDubbo(item.id, item.name, item.email))

    override fun update(item: User)= userService.update(UserDubbo(item.id, item.name, item.email))

    override fun delete(id: String)= userService.delete(id)


}